package cn.leetcode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Code17 {
    public static void main(String[] args) {
        Code17Demo code17Demo = new Code17Demo();
        List<String> list = code17Demo.letterCombinations("");
    }
}


class Code17Demo {

    Map<Character, String> phoneMap = new HashMap<Character, String>() {{
        put('2', "abc");
        put('3', "def");
        put('4', "ghi");
        put('5', "jkl");
        put('6', "mno");
        put('7', "pqrs");
        put('8', "tuv");
        put('9', "wxyz");
    }};


    public List<String> letterCombinations(String digits) {
        StringBuilder s = new StringBuilder();
        List<String> list = new ArrayList<>();
        fun(digits,s, 0, list);
        return list;
    }

    public void fun(String digits, StringBuilder s, int num, List<String> list){
        if(digits.length() != 0){
            if(s.length() == digits.length()){
                list.add(s.toString());
            }
        }
        if(num < digits.length()){
            char c = digits.charAt(num);
            String ss = phoneMap.get(c);
            for(int i = 0; i< ss.length(); i++){
                s.append(ss.charAt(i));
                fun(digits, s, num+1, list);
                s.deleteCharAt(s.length() - 1);
            }
        }
    }
}
